package com.mike.employment.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mike.employment.base.BaseDao;
import com.mike.employment.base.BaseServiceImpl;
import com.mike.employment.dao.AccountDao;
import com.mike.employment.dao.UserInfoDao;
import com.mike.employment.po.Account;
import com.mike.employment.po.UserInfo;
import com.mike.employment.service.UserInfoService;
import com.mike.employment.vo.UserVo;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

@Service
public class UserInfoServiceImpl extends BaseServiceImpl<UserInfo> implements UserInfoService{
	
	@Autowired
	private UserInfoDao userInfoDao;
	@Autowired
	private AccountDao accountDao;
	
	@PersistenceContext
	private EntityManager entityManager;
	
	@Override
	public BaseDao<UserInfo> getRepository() {
		return userInfoDao;
	}

	@Override
	public EntityManager getEntity() {
		return entityManager;
	}

	@Override
	public Account updateInfo(UserVo vo) {
		UserInfo info = userInfoDao.saveAndFlush(vo.getUser());
		Account account = accountDao.findById(vo.getAccount()).get();
		account.setUserInfo(info);
		return accountDao.saveAndFlush(account);
	}

}
